var  federalpurchases purchases1 purchases2  g1 g2 y1 y2 pi1 pi2  tau y g pi i c  p_c p2 p1 g_output pi_c;

varexo eps_g1 eps_g2;

parameters n gy zeta gamma rho_g1 rho_g2 sigma varphi beta phi_pi alpha1 alpha2 eta taylor std1 std2;

varphi    = 4;      // inverse of Frisch elasticity 
beta      = 0.997;   // monthly discount factor 
sigma     = 1;      // inverse IES
phi_pi    = 1.5;    // Taylor rule
eta       = 1;      // Elasticity of substitution
taylor    = 1;      // if true: taylor rule; if 0: inflation targeting

/* key parameters */
std1        = .1;   // std shock1 
std2        = .1;   // std shock2    
rho_g1      = .65;  // shock1 persistence
rho_g2      = .73;   // shock2 persistence
alpha1      = .78;  //   Calvo sector 1
alpha2      = .89;  //  Calvo sector 2
gy          = .2;   // G/Y
zeta        = 1-gy; // share of private consumption in GDP
gamma     = 0.26;     //.3 public consumption share sector 1
n         = 0.65;     //.85 size of sector 1    


model;
#omega = (n - gamma*(1-zeta))/zeta;
/* Market clearing in each sector */
n*y1 = - eta*omega*zeta*(1-omega)*tau + omega*zeta*c  + gamma*(1-zeta)*g1;    
(1-n)*y2 = eta*(1-omega)*zeta*omega*tau + (1-omega)*zeta*c + (1-gamma)*(1-zeta)*g2;

/* Phillips curves */
alpha1*pi1 = alpha1*beta*pi1(+1) + (1-alpha1)*(1-alpha1*beta)*(sigma*c + varphi*y1-(1-omega)*tau);       
alpha2*pi2 = alpha2*beta*pi2(+1) + (1-alpha2)*(1-alpha2*beta)*(sigma*c + varphi*y2+omega*tau);       

/* aggregate demand and aggregation */
phi_pi*pi_c  - taylor*(i - 0*y) = 0;



/*pi2 = 0;*/

sigma*c = sigma*c(+1) - (i - pi_c(+1));
pi_c = omega*pi1 + (1-omega)*pi2;
pi = n*pi1 + (1-n)*pi2;
y  = n*y1  + (1-n)*y2;
g  = gamma*g1 + (1-gamma)*g2;
tau = tau(-1) + pi1 - pi2;    

/* Government spending */
purchases1 = rho_g1*purchases1(-1) + std1*eps_g1;  
purchases2 = rho_g2*purchases2(-1) + std2*eps_g2;  
g1 = 0.16*purchases1;
g2 = 0.16*purchases2;        

federalpurchases = purchases1 + purchases2; /* facilitates representation for different runs: either one or the other */

pi2 = p2 - p2(-1);
pi1 = p1 - p1(-1);
pi_c = p_c - p_c(-1);

g_output = g*gy;

end;

shocks;

var eps_g1 = 1;
var eps_g2 = 1;

end;

/*************************************************************************/

check;

stoch_simul(irf=25,order=1,periods=200,nofunctions,nodisplay);
